New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ayana/logger

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ayana/logger

Useful and great looking logging made easy

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-68%
Maintainers
2
Weekly downloads
 
Created
Source

@ayana/logger NPM XO code style Install size

Useful and great looking logging made easy

What this is

This is a logging library inspired by the easy use of slf4j

How it helps with logging

Besides coloring your output, this logger makes it easy to log where you are logging from. This is done by some v8 StackTrace API magic. By that we can find out the module name and the path of your file in the module. This also works for modules in the node_modules folder. In addition the config is global, which makes it easy to control which modules and even single classes are allowed to log at which levels.

Limitaions

  • There is currently no way to change the logging levels or the logging output format (This can be changed if needed)
  • There is currently no way of putting the output to something else besides the stdout (Changing this is planned, see below)

Installation

With NPM

npm i @ayana/logger

With Yarn

yarn add @ayana/logger

Configuration

IMPORTANT: All projects that use this module SHOULD HAVE the code that is executed in one of the following folders (checked in the order listed): build, src, lib. If this is ignored the output might get messed up or the entire logger might stop working entirely. However you can add checked folders through the config with an array of strings. Note that this may impact on other modules using this logger.

Logger.setConfig({
    // The base logger level. This will be used if there's nothing specific defined in loggers. (Optional, Default: 'INFO')
    level: 'INFO',
    // Specifications for individual modules, packages and loggers. (Optional)
    loggers: [{
        name: 'helloworld:hello.Hello',
        level: 'DEBUG',
        // Whether the name should match exactly or if just the logger name starting with that name is enough (Optional, Default: false)
        exact: false,
    }],
    // Code directories to check besides 'build', 'src' and 'lib' (Optional)
    codeDirs: [
        'test',
    ],
});

Usage

Let's say your module is called helloworld and your JavaScript file is located in the folder src/hello. The filename doesn't matter.

const Logger = require('@ayana/logger');

const log = Logger.get('Hello');

class Hello {
    constructor() {
        log.info('Hello World!');
        // Example output: 2018-07-16 18:00:00:000 INFO  [helloworld:hello.Hello]: Hello World!
    }
}

// You can also create a logger using a reference to the class. This will then simply use the name of the class passed.
const logOfClass = Logger.get(Hello);

Future goals

  • Get rid of winston as it is quite large and most of its functionality is not needed
  • Allow more outputs besides stdout
  • Integrate well-looking logging of errors

GitLab repository

NPM package

License

Refer to the LICENSE file.

FAQs

Package last updated on 01 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc